package com.qgzj.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.qgzj.entity.Demo;
import com.qgzj.mapper.DemoMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DemoService {

    private static Logger logger = LoggerFactory.getLogger(DemoService.class);

    @Autowired
    DemoMapper demoMapper;


    public void insert() {
        Demo demo = new Demo();
        demo.setName("name1");
        demo.setDescption("111");
        demo.setVersion(1);
        demoMapper.insert(demo);
        Demo demo2 = new Demo();
        demo2.setName("name1");
        demo2.setDescption("222");
        demo2.setVersion(1);
        demoMapper.insert(demo2);
        Demo demo3 = new Demo();
        demo3.setName("name3");
        demo3.setDescption("333");
        demo3.setVersion(1);
        demoMapper.insert(demo3);
    }

    public List<Demo> select() {
        List<Demo> objects = demoMapper.selectList(new EntityWrapper<Demo>().eq("name", "name1"));
        return objects;
    }

    public void update() {
        Demo demo = new Demo();
        demo.setName("name1");
        demo.setDescption("update to version 2");
        demo.setVersion(2);
        demoMapper.updateByName(demo);
        Demo demo2 = new Demo();
        demo2.setName("name3");
        demo2.setDescption("update to version 2");
        demo2.setVersion(2);
        demoMapper.updateByName(demo2);
//        Demo demo2 = new Demo();
//        demo2.setName("name3");
//        demo2.setDescption("update to version 4");
//        demo2.setVersion(4);
//        demoMapper.update(demo2,new EntityWrapper<Demo>().eq("name", "name3"));

    }


}
